<?php
/*
 * Prehlad ziakov ktori este temu nemaju priradenu a tych ktori
 * temu uz maju s moznostou priradenia aktualne volnych tem.
 */


if(isset($_POST["studentchange"])){
  $functs->change_student($_POST["id"],$_POST["meno"],$_POST["priezvisko"],$_POST["email"]);
}

//Pridanie
if(isset($_POST["pridaj"])&&$_POST["pridaj"]==" " && $_POST["meno"]!="" && $_POST["priezvisko"]!="" && $_POST["email"]!=""){
  echo "INSERT INTO pouzivatel (meno,priezvisko,email) VALUES('".$_POST["meno"]."','".$_POST["priezvisko"]."','".$_POST["email"]."')";
  mysql_query("INSERT INTO pouzivatel (rola_id,meno,priezvisko,email) VALUES(2,'".$_POST["meno"]."','".$_POST["priezvisko"]."','".$_POST["email"]."')");
  
}

//Zmazanie
if(isset($_GET["del"])){
  mysql_query("DELETE FROM pouzivatel WHERE pouzivatel_id=".$_GET["del"]);
}
?>

<?php if(!isset($_GET["edit"])){?>



  <div id="head-uc-studenti"></div>

  <div id="tops-u"></div>
  <div id="tops-m">
    <form action="?mod=list_stud" method="post">
      <table id="tab">
        <tr><th colspan="3"> <div class="textorange">Nový študent:</div> </th></tr>
        <tr>
          <td width="140"></td>
          <td><div class="bielynadpis">Meno: </div></td>
          <td><input class="vstup" type="text" name="meno"/></td>
        </tr> 
        <tr>
          <td></td>
          <td><div class="bielynadpis">Priezvisko: </div></td>
          <td><input class="vstup" type="text" name="priezvisko"/></td>
        </tr>
        <tr>
          <td></td>
          <td><div class="bielynadpis">Email: </div></td>
          <td><input class="vstup" type="text" name="email"/></td>
        </tr>  
        <tr>
          <td colspan="2"></td>
          <td align="right"><input class="pridaj" type="submit" name="pridaj" value=" "/></td>
        </tr>
      </table>
    </form>
  </div>
  <div id="tops-b"></div>  

  <div id="topm-u">
    <div id="head-uc-zoznam-zmeny"></div>
  </div>
  <div id="topm-m">
    <table id="tab" cellspacing="0" cellpading="0">
      <tr align="center">
        <th><div class="bielyth">Meno</div></th>
        <th><div class="bielyth">E-mail</div></th>
        <th><div class="bielyth">Zmeny</div></th>
        <th><div class="bielyth">Zmaž</div></th>
      </tr>
          <?php
            $result=$functs->select_student("");$poc=0;
            while($array=mysql_fetch_array($result)){
              
              if($poc%2==0) echo '<tr class="one">';
              else echo '<tr class="two">';
              
              echo '<td><div class="back" style="width:267px;">'.$array['meno'].' '.$array['priezvisko'].'</div></td>';
              echo '<td><div class="back" style="width:267px;">'.$array['email'].'</div></td>';
              echo '<td><div class="back" style="width:33px;"><a href="?mod=list_stud&edit='.$array['pouzivatel_id'].'"><div class="icon-edit"></div></a></div></td>';
              echo '<td><div class="back" style="width:33px;"><a onclick="return confirm(\'Naozaj zmazať?\')"  href="?mod=list_stud&del='.$array['pouzivatel_id'].'"><div class="icon-del"></div></a></div></td></tr>';
              
              $poc++;
            }
          ?>
    </table>
  </div>
  <div id="topm-b"></div>


<?php
}else{
?>

  <div id="head-uc-studenti"></div>
  
    <div id="tops-u"></div>
    <div id="tops-m">
  
    <form action="?mod=list_stud" method="post">
    <table id="tab">
          <?php
            $result=$functs->select_student($_GET["edit"]);//mysql_query("SELECT * FROM user WHERE role='student' AND id='".$_GET["edit"]."'");
            $array=mysql_fetch_array($result);
              echo '<tr><td><div class="bielynadpis">Meno: </div></td>';
              echo '<td><input type="text" name="meno" value="'.$array['meno'].'"/></td></tr>';
              echo '<tr><td><div class="bielynadpis">Priezvisko: </div></td>';
              echo '<td><input type="text" name="priezvisko" value="'.$array['priezvisko'].'"/></td></tr>';
              echo '<tr><td><div class="bielynadpis">E-mail: </div></td>';
              echo '<td><input type="text" name="email" value="'.$array['email'].'"/></td></tr>';
              echo '<tr><td colspan="2" align="center">';
              echo '<input type="submit" class="zmen" name="studentchange" value=" "/>';
              echo '<input type="hidden" name="id" value="'.$_GET["edit"].'"/></td></tr>'
          ?>
    </table>
    </form>
  </div>
  <div id="topm-b"></div>
  
<?php
}
?>